package 单周赛.history;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 */
public class 第290场单周赛 {

    public static void main(String[] args) {

        int[][] nums = {{3, 1, 2, 4, 5}, {1, 2, 3, 4}, {3, 4, 5, 6}};
        System.out.println(intersection(nums));

        // 141
        int[][] nu1 = {{8, 9, 6}, {9, 8, 4}, {4, 1, 1}, {8, 5, 1}, {7, 1, 1}, {6, 7, 5}, {7, 1, 1}, {7, 1, 1}, {5, 5, 3}};
        int[][] nu = {{2, 2, 2}, {3, 4, 1}};
        int[][] nu2 = {{8, 9, 6}};

    }

    public static List<Integer> intersection(int[][] nums) {
        List<Integer> list = new ArrayList<>();
        Set<Integer> preSet = new HashSet<>();
        for (int num : nums[0]) {
            preSet.add(num);
        }
        for (int i = 1; i < nums.length; i++) {
            Set<Integer> curSet = new HashSet<>();
            for (int num : nums[i]) {
                if (preSet.contains(num)) {
                    curSet.add(num);
                }
            }
            preSet = curSet;
            if (preSet.size() == 0) return new ArrayList<>();
        }
        for (Integer num : preSet) {
            list.add(num);
        }
        list.sort((o1, o2) -> o1 - o2);
        return list;
    }

}
